grid = [[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
        [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
        [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]]

result = 0


def enter(i, j):
    if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[:][0]):
        return 0

    if (grid[i][j] == 0):
        return 0
    total = 1
    grid[i][j] = 0

    total = total + enter(i + 1, j)
    total = total + enter(i - 1, j)
    total = total + enter(i, j + 1)
    total = total + enter(i, j - 1)
    return total


for i in range(len(grid)):
    for j in range(len(grid[:][0])):
        if grid[i][j] == 1:
            result = max(enter(i, j), result)

print(result)
